﻿/******************************************************************************
 *
 * @copyright:          Copyright 2011 UniSky Ltd.
 * @file:
 * @author:              kenping.liu
 * @creation:
 * @description:
 *
 * @modifications
 * date         user                description
 *
 *
 * @more-details
 *
 *****************************************************************************/

#include "u/u_hls.h"
#include "u/u_util.h"

U_NAMESPACE_BEGIN(u)
U_NAMESPACE_BEGIN(hls)

//#EXTM3U
//#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=258014
//cdtv1_5/sub.m3u8
//#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=360188
//cdtv1_4/sub.m3u8
//#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=564536
//cdtv1_3/sub.m3u8
//#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=871058
//cdtv1_2/sub.m3u8
//#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=1229471
//cdtv1_1/sub.m3u8
//#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=52710
//cdtv1_4/64k_sub.m3u8
void M3U8::parse_program(PROGRAM_M3U8* program, const char* _Content)
{
    u::util::Str::Array lines;
    std::string content(_Content);
    
    program->stmcnt = 0;
    ZeroMemory(program->streams, sizeof(STREAM_M3U8)*10);

    u::util::Str::split(lines, content, "\n", false);
    for ( size_t i=0; i<(lines.size()-1); i++ )
    {
        std::string::size_type pos = lines[i].find("BANDWIDTH=");
        if ( lines[i].at(0)=='#' && pos!=std::string::npos && lines[i+1].at(0)!='#' )
        {
            program->streams[program->stmcnt].bandwidth = atoi(lines[i].substr(pos+10).c_str());
            u_sprintf(program->streams[program->stmcnt].path, "%s", lines[i+1].c_str());
            program->stmcnt++;
        }
    }
}

//
//#EXTM3U
//#EXT-X-TARGETDURATION:10
//#EXT-X-MEDIA-SEQUENCE:737
//#EXTINF:10,
//./1fileSequence737.ts
//#EXTINF:10,
//./1fileSequence738.ts
//#EXTINF:10,
//./1fileSequence739.ts
//#EXTINF:10,
//./1fileSequence740.ts
//#EXTINF:10,
//./1fileSequence741.ts
void M3U8::parse_stream(STREAM_M3U8* stream, const char* _Content)
{
    u::util::Str::Array lines;
    std::string content(_Content);


}

U_NAMESPACE_END(hls)
U_NAMESPACE_END(u)
